<?php
class Comments extends Model {
	function Comments(){
		parent::Model();
    }
    
    function getComment($post_id){
    	$return = FALSE;
    	$query = "SELECT * FROM posts_comments WHERE post_id='$post_id' ORDER BY id ASC";
    	$query = $this->db->query($query);
   	 	if($query->num_rows() > 0){
   	 		foreach ($query->result() as $row){
				$return['user_id'] []  = $row->user_id;
				$return['message'] [] = $row->message;
				$return['date'] [] = $row->date;
			}
    	}
    	return $return;
    }
    function getCommentDistinctUser($post_id){
    	$query = "SELECT DISTINCT user_id FROM posts_comments WHERE post_id='$post_id'";
    	$query = $this->db->query($query);
   	 	if($query->num_rows() > 0){
   	 		foreach ($query->result() as $row){
				$return['user_id'] []  = $row->user_id;
			}
    	}
    	return $return;
    }
    
    function insertComment($user_id=NULL,$post_id=NULL,$commenttext=NULL){
    	$query = "INSERT INTO posts_comments (post_id,user_id,message,date) VALUES ('$post_id','$user_id','$commenttext','".time()."')";
   		return $this->db->query($query);
    }
}